set -xe

export build_njobs=${build_njobs:-18}

# define include_torch_eval to link libtorch
bazel build --jobs ${build_njobs} -c opt --strip=always --define include_torch_eval=1 //cc/appcoin2/strategy/lm:runner
bazel build --jobs ${build_njobs} -c opt --strip=always --define include_torch_eval=1 //cc/appcoin2/strategy/lm:sim

COIN_ROOT="$(git rev-parse --show-toplevel)"
COIN_BINARY_ROOT=$COIN_ROOT/../coin_binary

function deploy_coin2_app {
  SOURCE_FILE=$COIN_ROOT/bazel-bin/$1/$3
  TARGET_DIR=$COIN_BINARY_ROOT/coin2-bazel-bin-3.10/$2
  mkdir -p $TARGET_DIR
  rsync -avh --delete -L $SOURCE_FILE $TARGET_DIR
}

set -x
deploy_coin2_app cc/appcoin2/strategy/lm cc/appcoin2/strategy/dm runner
deploy_coin2_app cc/appcoin2/strategy/lm cc/appcoin2/strategy/dm sim
echo "Build and Copy to coin_binary Successfully!!"
